<template>
  <el-form-item :label="i18nt('designer.setting.customClass')">
    <el-select
      v-model="localOptionModel.customClass"
      multiple
      filterable
      allow-create
      default-first-option
    >
      <el-option v-for="(item, idx) in cssClassList" :key="idx" :label="item" :value="item" />
    </el-select>
  </el-form-item>
</template>

<script>
import i18n from '@/utils/i18n'
import { deepClone } from '@/utils/util'
import { reactive, toRefs } from 'vue'
export default {
  name: 'CustomClassEditor',
  componentName: 'PropertyEditor',
  mixins: [i18n],
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object
  },
  data() {
    return {
      localOptionModel: this.optionModel,
      cssClassList: []
    }
  },
  watch: {
    // Watch for changes in the local model and emit an event to update the parent component
    localOptionModel(newValue) {
      this.$emit('update:optionModel', this.localOptionModel)
    },

    // Also make sure to update the local model if the prop changes externally
    optionModel(newVal) {
      this.localOptionModel = newVal
    }
  },
  created() {
    this.cssClassList = deepClone(this.designer.getCssClassList())
    //监听表单css代码改动事件并重新加载！
    this.designer.handleEvent('form-css-updated', (cssClassList) => {
      this.cssClassList = cssClassList
    })
  }
}
</script>

<style scoped></style>
